var rootview = ui("$");
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var do_Global = sm("do_Global");
var helperOpen = require("helper/open");
var order = require("helper/order");

var activityUrl = require("url/activity");
var httpUrl = activityUrl.url.sign.cancle;
var qqHttp = require("helper/http");
var helperOpen = require("helper/open");
//UI
var buttonDel=ui("buttonDel");
var buttonOrder=ui("buttonOrder");
var layoutRoot=ui("layoutRoot");
var activityTitle=ui("activityTitle");
var activityState=ui("activityState");

rootview.setMapping({   // 此处的Mapping只能设置在 RootView 上 ;
	"layoutRoot.tag":"id",
	"activityTitle.tag" : "orderNo",
    "activityTitle.text" : "activityName",
    "activityState.text" : "showStatus",
    "activityState.tag" : "activityStatus",
    "activityPrice.text" : "showCost",
    "activityAddr.text" : "activityAddress",
});

rootview.on("dataRefreshed", function(){
	if(activityState.tag==2){
		buttonDel.text="取消报名";
	}else{
		buttonDel.text="删除记录";
	}
	if(null==activityTitle.tag||''==activityTitle.tag){
		buttonDel.visible=true;
		buttonOrder.visible=false;
	}else{
		buttonDel.visible=false;
		buttonOrder.visible=true;
	}
});
/*buttonOrder.on("touch",function(){//去订单
	helperOpen.open("source://view/order/detail.ui", {orderNo : activityTitle.tag});
})*/
buttonOrder.on("touch",function(){//去订单
	helperOpen.open("source://view/order/list.ui");
})
buttonDel.on("touch",function(){
	var str;
	if(activityState.tag==2){
		str="取消报名";
	}else{
		str="删除记录";
	}
	nf.confirm("您确实要"+str+"吗？", str, "确定", "取消", function(data, e) {
		if(data == 1){
			del();
		}
	})
})
function del(){
	var params = {
		id: layoutRoot.tag
	};
	qqHttp.post(httpUrl, params, function(data) {
		nf.toast("取消成功");
		do_Page.fire("cancleActivity",layoutRoot.tag);
	})
}